package chapter9.demo;

/**
 * @Author juzipi
 * @Date 2021/6/21 16:24
 * @Info
 */
public class RecursionTest {

    public static void main(String[] args) {
        //递归！
        //输出1+2+3+...+100
        RecursionTest recursionTest = new RecursionTest();
        System.out.println(recursionTest.getSum(0));

        //拓展
        //变量是基本数据类型保存的是数据值
        //变量是引用数据类型保存的是引用地址
        System.out.println(recursionTest.f(10));
        String name = "zhangsa";
        recursionTest.change(name);
        System.out.println(name);
    }

    public void change(String s){
        s = "nihao";
    }

    public static int i = -1;

    public int getSum(int sum){
        if (sum == 100){
            return 1;
        }else {
            return i+getSum(i++);
        }
    }
    //

    public int f(int n){
        if (n == 0){
            return 1;
        }else if (n == 1){
            return 4;
        }
        else {
            //f(n+2) = 2*f(n+1) + f(n)
            return 2*f(n-1)+f(n-2);
        }
    }

}
